package suncertify.view;

import suncertify.service.Service;

import javax.swing.table.AbstractTableModel;
import java.util.List;
import java.util.ArrayList;

/**
 * Implementation of server model for Service class
 */
public class TableAdapter extends AbstractTableModel {
    private Service service;

    /**
     * constructor
     * @param service data service
     */
    public TableAdapter(Service service) {
        this.service = service;
    }

    /**
     * returns rows count
     * @return rows count
     */
    public int getRowCount() {
        return service.getRowCount();
    }

    /**
     * returns columns count
     * @return columns count
     */
    public int getColumnCount() {
        return service.getColumnCount();
    }

    /**
     * return value at cell
     * @param r row number
     * @param c column number
     * @return cell value
     */
    public Object getValueAt(int r, int c) {
        String val = service.get(r, c);
        if (val != null && val.length() > 0) {
            val = val.trim();
        }
        return val;
    }

    /**
     *  ask the editor if it can start editing using row and column indexes
     * @param row the index of the row
     * @param col the index of the column
     * @return true if editing can started
     */
    public boolean isCellEditable(int row, int col) {
        return false;
    }

    /**
     * returns the name of the column at columnIndex.
     * @param col the index of the column
     * @return the name of the column
     */
    public String getColumnName(int col) {
        return service.getColumnName(col);
    }

    /**
     * sets the value in the cell at columnIndex and rowIndex to aValue
     * @param value the new value
     * @param row the row whose value is to be changed
     * @param col the column whose value is to be changed
     */
    @Override
    public void setValueAt(Object value, int row, int col) {
        super.setValueAt(value, row, col);
    }
}
